<template>
    <a-modal
      title="文件列表"
      :width="600"
      v-model="fileListVisible"
      :maskClosable="false"
      @ok="fileListSubmit"
      @cancel="fileListCancel"
    >
      <s-table
        bordered
        style="margin-top: 20px"
        size="default"
        ref="fileListtable"
        rowKey="unid"
        :columns="fileListColumns"
        :data="fileListLoadData"
      >
        <span slot="fileListAction" slot-scope="text, record">
          <a @click="downFile(record)">下载</a>
        </span>
      </s-table>
    </a-modal>
</template>
<script>
import { openUpload, getList as getFilesList,  delAttachment as delGwfjFiles, downloadFile  } from "@/api/common/gwfjFiles"
import { STable } from "../../../components";

export default {
    name: "GwfjFilesListModal",
    components: {
        STable,
    },
    data() {
        return {
            fileListVisible: false,
            fileListColumns: [
                {
                    title: "序号",
                    width: "80px",
                    customRender: (text, record, index) => `${index + 1}`, // 显示每一行的序号
                },
                {
                    title: "附件名称",
                    dataIndex: "attachName",
                },
                {
                    title: "操作",
                    dataIndex: "action",
                    scopedSlots: { customRender: "fileListAction" },
                },
            ],
            fileListLoadData: (paramter) => {
                paramter.fjUnid = this.fjUnid
                return getFilesList(paramter).then((res) => {
                    console.log(res.result,"-=-=-=-=")
                    return res.result;
                });
            }
        }
    },
    methods: {
        fileListSubmit() {
            this.fileListVisible = false
        },
        fileListCancel() {
            this.fileListVisible = false
        },
        showFileList(unid) {
            this.fileListVisible = true
            this.fjUnid = unid;
            this.$nextTick(() => {
                this.$refs.fileListtable.refresh(true);
            })
        },
        downFile(file) {
            window.open(downloadFile(file.unid))
        },
    }
}
</script>
